<template>
  <view>
    <!-- 选择收货地址 -->
    <view class="choose-adress" v-if="JSON.stringify(address) === '{}'">
      <button type="primary" size="mini" @click="chooseAdress">选择收货地址</button>
    </view>
    
    <!-- 收货地址渲染 -->
    <view class="adress-info" v-else @click="chooseAdress">
      <view class="row1">
        <view class="row1-left">收货人：{{address.userName}}</view>
        <view class="row1-right">电话：{{address.telNumber}}</view>
      </view>
      <view class="row2">
        <view class="row2-left">收货地址：</view>
        <view class="row2-right">{{addStr}}</view>
      </view>
    </view>
    
    <!-- 底部的边框线 -->
    <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapMutations,mapState,mapGetters} from 'vuex'
  export default {
    name:"my-adress",
    data() {
      return {
        // address:{}
      };
    },
    methods:{
      ...mapMutations('m_address',['addAddress']),
    async  chooseAdress(){
      const [error,success] =  await uni.chooseAddress()
      console.log(error,success)
      if(error===null && success.errMsg === 'chooseAddress:ok'){
        // this.address = success
        //向vuex中存地址
        this.addAddress(success)
      }
      }
    },
    computed:{
      ...mapState('m_address',['address']),
      ...mapGetters('m_address',['addStr'])
    }
  }
</script>

<style lang="scss">
.choose-adress{
  display: flex;
  justify-content: center;
  align-items: center;

  height: 90px;
}

.adress-info{
  font-size: 12px;
  padding: 0 5px;
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  .row1{
    display: flex;
    justify-content: space-between;
    .row1-left{
      
    }
    .row1-right{
      
    }
  }
  .row2{
    display: flex;
    margin-top: 10px;
    align-items: center;
    .row2-left{
      white-space: nowrap;
    }
    .row2-right{}
  }
  
  
}

.address-border {
  display: block;
  width: 100%;
  height: 5px;
  }

</style>